package smetana.domain;

/**
 * @author dmitry.mamonov
 */
public abstract class AbstractEntity implements IntId {

    @Override
    public boolean equals(Object other) {
        if (this == other) return true;
        if (other == null) return false;
        if ((this.getClass().isAssignableFrom(other.getClass()) == false) &&
                (other.getClass().isAssignableFrom(this.getClass()) == false)) {
            return false;
        }

        AbstractEntity that = (AbstractEntity) other;

        if (getId() != that.getId()) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return getId();
    }

    @Override
    public String toString() {
        return new StringBuilder()
                .append(getClass().getSimpleName())
                .append("[")
                .append(getId())
                .append("]")
                .toString();
    }
}
